//
//  UserAPI.m
//  RainbowFM
//
//  Created by chenli on 14/12/17.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "UserAPI.h"
#import "AFAppDotNetAPIClient.h"

@implementation UserAPI

-(void)fetchUserProfileWithUserID:(NSString *)userID result:(void (^)(NSDictionary *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AAM_BASE_URL
                                   parameters:@{@"serviceName" : @"aam_user_Info_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userID}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}


-(void)fetchUserAddressWithUserID:(NSString *)userID currentPage:(NSString *)start pageSize:(NSString *)count result:(void (^)(NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AAM_BASE_URL
                                   parameters:@{@"serviceName" : @"aam_deli_addr_list_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userID,
                                                              @"pageSize" : count,
                                                              @"currentPage" : start}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}



-(void)editUserProfileWithUserID:(NSString *)userID mgrField:(NSString *)mgr userTel:(NSString *)userTel_ userOldPwd:(NSString *)userOldPwd_ smsValidateToken:(NSString *)smsCode userPwd:(NSString *)userPwd_ nickName:(NSString *)nickName_ sex:(NSString *)sex_ birthDay:(NSString *)birthDay_ address:(NSString *)address_ sign:(NSString *)sign_ headPic:(NSString *)headPic_ result:(void (^)(BOOL))res{
    
    NSDictionary *dict = @{@"mgrField" : mgr,
                           @"userId" : userID,
                           @"userTel" : userTel_ == nil ? @"" : userTel_,
                           @"userOldPwd" : userOldPwd_ == nil ? @"" : userOldPwd_,
                           @"smsValidateToken" : smsCode == nil ? @"" : smsCode,
                           @"userPwd" : userPwd_ == nil ? @"" : userPwd_,
                           @"nickName" : nickName_ == nil ? @"" : nickName_,
                           @"sex" : sex_ == nil ? @"" : sex_,
                           @"birthday" : birthDay_ == nil ? @"" : birthDay_,
                           @"address" : address_ == nil? @"" : address_,
                           @"sign" : sign_ == nil ? @"" : sign_,
                           @"headPic" : headPic_ == nil ? @"" : headPic_};
    
    [[AFAppDotNetAPIClient sharedClient] POST:AAM_BASE_URL
                                   parameters:@{@"serviceName" : @"aam_user_mgr_req",
                                                @"callType" : @"002",
                                                @"params" : dict}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES);
                                          }
                                          else{
                                              res(NO);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
    
}


-(void)userManageAddressWithOper:(NSString *)oper deliID:(NSString *)deliId userID:(NSString *)userId deliName:(NSString *)name deliTel:(NSString *)tel deliAreaAddr:(NSString *)areaAddr deliDtlAddr:(NSString *)dtlAddr result:(void (^)(BOOL))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AAM_BASE_URL
                                   parameters:@{@"serviceName" : @"aam_deli_addr_mgr_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"oper" : oper,
                                                              @"deliId" : deliId,
                                                              @"userId" : userId,
                                                              @"deliName": name,
                                                              @"deliTel" : tel,
                                                              @"deliAreaAddr" : areaAddr,
                                                              @"deliDtlAddr" : dtlAddr}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES);
//                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(NO);
//                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
    
}


-(void)fetchUserAddressDetailWithUserID:(NSString *)userId deliID:(NSString *)deliId result:(void (^)(NSDictionary *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AAM_BASE_URL
                                   parameters:@{@"serviceName" : @"aam_deli_addr_dtl_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"deliId" : deliId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}

@end
